﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AppBox.admin
{
    public partial class config : PageBase
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            tbxTitle.Text = XConfigHelper.Title;
            nbxPageSize.Text = XConfigHelper.PageSize.ToString();
            //ddlMenuType.SelectedValue = XConfigHelper.MenuType.ToLower();
            tbxHelpList.Text = StringUtil.GetJSBeautifyString(XConfigHelper.HelpList);
        }

        #endregion

        #region Events

        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            string helpListStr = tbxHelpList.Text.Trim();
            try
            {
                new Nii.JSON.JSONArray(helpListStr);
            }
            catch (Exception)
            {
                tbxHelpList.MarkInvalid("格式不正确，必须是JSON字符串！");

                return;
            }



            XConfigHelper.Title = tbxTitle.Text.Trim();
            XConfigHelper.PageSize = Convert.ToInt32(nbxPageSize.Text.Trim());
            //if (XConfigHelper.MenuType != ddlMenuType.SelectedValue.ToLower())
            //{
            //    XConfigHelper.MenuType = ddlMenuType.SelectedValue.ToLower();
            //    menuTypeChanged = true;
            //}
            XConfigHelper.HelpList = helpListStr;
            XConfigHelper.SaveAll();

            ExtAspNet.Alert.ShowInParent("修改系统配置成功！");

        }

        #endregion
    }
}
